package com.easy.controller;

import com.easy.bean.Fruit;
import com.easy.service.FruitService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("fruit")
public class FruitController {
    @Autowired
    FruitService fruitService;

    @PostMapping
    public Result add(@RequestBody Fruit fruit){
        Object obj = fruitService.add(fruit);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody Fruit fruit){
        Object obj = fruitService.edit(fruit);
        return Result.success(obj);
    }

    @DeleteMapping("{fruit_id}")
    public Result delete(@PathVariable("fruit_id") Integer fruit_id){
        Object obj = fruitService.del(fruit_id);
        return Result.success(obj);
    }

    @GetMapping("{fruit_id}")
    public Result one(@PathVariable("fruit_id") Integer fruit_id){
        Object obj = fruitService.one(fruit_id);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all(Fruit fruit){
        Object obj = fruitService.all(fruit);
        return Result.success(obj);
    }

    @GetMapping("page")
    public Result page(Page page, Fruit fruit){
        fruitService.page(page,fruit);
        return Result.success(page);
    }
}
